const {
    Sequelize
} = require('sequelize')
const initModels = require('../models/init-models')

const {
    database,
    username,
    password,
    host
} = require('../../config/config').db_config

// 方法 3: 分别传递参数 (其它数据库)
const sequelize = new Sequelize(database, username, password, {
    host,
    dialect: 'mysql',
    // logging: true, //日志输出
    timezone: '+08:00', //时区同步
    dialectOptions: { // 时间格式化
        charset: 'utf8mb4',
        dateStrings: true,
        typeCast: true
    },
     // define: {
     //     //create_time  update_time delete_time
     //     timestamps: true, //时间戳
     //     paranoid: true, //软删除 必须启用时间戳
     //     createdAt: 'created_at', //创建时间表字段名称重定义
     //     updatedAt: 'updated_at',
     //     deletedAt: 'deleted_at',
     //     underscored: true, //驼峰转下划线
     //     freezeTableName: true, //不修改表名
     //     scopes: {
     //         bh: {
     //             attributes: {
     //                 exclude: ['updated_at', 'deleted_at', 'created_at']
     //             }
     //         }
     //     }
     // }
})

try {
    sequelize.authenticate();
    console.log('🎉 Connection has been established successfully.')
} catch (error) {
    console.error('❌ Unable to connect to the database:', error)
}

module.exports = initModels(sequelize)